package com.ruoyi.project.jsrh.news.controller;

import java.util.List;

import com.ruoyi.project.jsrh.news.domain.ZtNewsInfo;
import com.ruoyi.project.jsrh.news.service.IZtNewsInfoService;
import com.ruoyi.project.jsrh.news.service.IZtNewsTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 记录资讯详细信息Controller
 * 
 * @author ruoyi
 * @date 2020-06-09
 */
@Controller
@RequestMapping("/jsrh/news")
public class ZtNewsInfoController extends BaseController
{
    private String prefix = "jsrh/news";

    @Autowired
    private IZtNewsInfoService ztNewsInfoService;

    @Autowired
    private IZtNewsTypeService ztNewsTypeService;


    @RequiresPermissions("jsrh:news:view")
    @GetMapping()
    public String info(ModelMap mmap)
    {
        mmap.put("ztNewsType", ztNewsTypeService.selectZtNewsTypeList(null));
        return prefix + "/info";
    }

    /**
     * 查询记录资讯详细信息列表
     */
    @RequiresPermissions("jsrh:news:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZtNewsInfo ztNewsInfo)
    {
        startPage();
        List<ZtNewsInfo> list = ztNewsInfoService.selectZtNewsInfoList(ztNewsInfo);

        return getDataTable(list);
    }

    /**
     * 导出记录资讯详细信息列表
     */
    @RequiresPermissions("jsrh:news:export")
    @Log(title = "记录资讯详细信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZtNewsInfo ztNewsInfo)
    {
        List<ZtNewsInfo> list = ztNewsInfoService.selectZtNewsInfoList(ztNewsInfo);
        ExcelUtil<ZtNewsInfo> util = new ExcelUtil<ZtNewsInfo>(ZtNewsInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 新增记录资讯详细信息
     */
    @GetMapping("/add")
    public String add( ModelMap mmap)
    {
        mmap.put("ztNewsType", ztNewsTypeService.selectZtNewsTypeList(null));

        return prefix + "/add";
    }

    /**
     * 新增保存记录资讯详细信息
     */
    @RequiresPermissions("jsrh:news:add")
    @Log(title = "记录资讯详细信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZtNewsInfo ztNewsInfo)
    {
        return toAjax(ztNewsInfoService.insertZtNewsInfo(ztNewsInfo));
    }

    /**
     * 修改记录资讯详细信息
     */
    @GetMapping("/edit/{newsId}")
    public String edit(@PathVariable("newsId") Long newsId, ModelMap mmap)
    {
        ZtNewsInfo ztNewsInfo = ztNewsInfoService.selectZtNewsInfoById(newsId);
        mmap.put("ztNewsInfo", ztNewsInfo);

        mmap.put("ztNewsType", ztNewsTypeService.selectZtNewsTypeList(null));

        return prefix + "/edit";
    }

    /**
     * 修改保存记录资讯详细信息
     */
    @RequiresPermissions("jsrh:news:edit")
    @Log(title = "记录资讯详细信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZtNewsInfo ztNewsInfo)
    {
        return toAjax(ztNewsInfoService.updateZtNewsInfo(ztNewsInfo));
    }

    /**
     * 删除记录资讯详细信息
     */
    @RequiresPermissions("jsrh:news:remove")
    @Log(title = "记录资讯详细信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ztNewsInfoService.deleteZtNewsInfoByIds(ids));
    }
}
